﻿Imports MetodosComuns
Imports extranet.BC
Imports extranet.BE
Imports System.Collections
Imports System.Collections.Generic

Partial Class Eventos_AdmEvtEnviarEmail
    Inherits System.Web.UI.Page

    Protected Sub btnVoltar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnVoltar.Click
        Response.Redirect("AdmEvtGerenciamentoEvento.aspx?Evento=" & Request.QueryString("Evento"))
    End Sub

    Protected Sub btnEnviar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnviar.Click
        Try
            MetodosComuns.EnviaEmail(txtDestinatario.Text, FreeTextBox1.Text, txtAssunto.Text, lblEmailRemetente.Text, txtNomeRemetente.Text)

            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("alert(""Emails Enviados com sucesso!"")" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
        Catch ex As ApplicationException
            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("alert(""Erro Enviando Email: " & ex.Message & """)" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
        End Try
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        '==================       PROCEDIMENTO  PADRÃO  SEGURANÇA     =============================
        Dim objBESeguranca As BESeguranca
        Dim objBEUsuario As BEUsuario = Session("objBEUsuario")
        If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
        Session("strTela") = MetodosComuns.GetCurrentPageName()
        If Not IsPostBack Then          ' SEGURANÇA
            objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
            If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
            Session("objBESeguranca") = objBESeguranca
        Else
            objBESeguranca = Session("objBESeguranca")
        End If

        If Not IsPostBack Then
            Dim lstInscritosEmail As List(Of String) = Session("lstInscritosEmail")
            txtDestinatario.Text = ""
      'For i As Integer = 0 To lstInscritosEmail.Count - 1
      '    Dim objBEInscrito As BEInscrito = BCInscrito.SelecionarInscrito(lstInscritosEmail(i))
      '    txtDestinatario.Text &= objBEInscrito.Email
      '    If Not i = lstInscritosEmail.Count - 1 Then
      '        txtDestinatario.Text &= "; "
      '    End If
      'Next
            lblEmailRemetente.Text = MetodosComuns.STREMAILFIT4
        End If
    End Sub
End Class
